Skip to content

Conversation

@SmartManoj
Copy link
Contributor

@SmartManoj SmartManoj commented Nov 4, 2025

Introduces WindowsTerminal for PowerShell-based command execution on Windows systems. Updates factory and init logic to conditionally import and use platform-specific terminal backends, ensuring compatibility across Windows and Unix-like platforms.

image

Introduces WindowsTerminal for PowerShell-based command execution on Windows systems. Updates factory and init logic to conditionally import and use platform-specific terminal backends, ensuring compatibility across Windows and Unix-like platforms.
@xingyaoww xingyaoww requested a review from ryanhoangt November 4, 2025 15:42
Copy link
Collaborator

@xingyaoww xingyaoww left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we should rename the tool execute_bash into execute_terminal because of the powershell here? 🤔

And we tell the agent if it is using powershell vs bash. But we can do this in subsequent pr

Simplifies the code by unconditionally importing fcntl and pty, removing the platform-specific logic and dummy assignments for Windows. This module is intended for Unix-like systems only.
@SmartManoj
Copy link
Contributor Author

image

Deleted scripts/demo.py as it is no longer needed. The demo script previously demonstrated basic usage of the OpenHands SDK and agent setup.
Eliminated an erroneous 'n' character from the import block in terminal_session.py to clean up the code and prevent potential syntax errors.
Changed assertions in test_windows_terminal_close_and_reopen to check 'obs.text' instead of 'obs.output' for command results. This aligns the test with the updated observation object structure.
@xingyaoww
Copy link
Collaborator

@SmartManoj can you resolve merge conflicts/

Update the terminal module's __init__.py to conditionally import WindowsTerminal on Windows and SubprocessTerminal/TmuxTerminal on other platforms. This change ensures only relevant terminal classes are exposed based on the operating system.
Removed the deprecated execute_bash.terminal package and updated all relevant imports to use the new openhands.tools.terminal.terminal structure. This change consolidates terminal-related code under a single module for improved maintainability and clarity.
@blacksmith-sh
Copy link
Contributor

blacksmith-sh bot commented Nov 10, 2025

[Automatic Post]: This PR seems to be currently waiting for review. @ryanhoangt, could you please take a look when you have a chance?

@SmartManoj SmartManoj requested a review from xingyaoww November 15, 2025 11:12
Copy link
Collaborator

@ryanhoangt ryanhoangt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the PR. When testing the PR on the examples/01_hello_world.py and adjusting the message to something like "Please check the current directory, list all files and then exit.", I saw it first attempted to run a bash command with &&, which failed in PowerShell. However, it didn't fail instantly, it got stuck in soft timeout observation loop and the agent decided to reset the terminal. Do you have any ideas why it happened?

]
# Conditionally import platform-specific terminals
if platform.system() == "Windows":
from openhands.tools.terminal.terminal.windows_terminal import WindowsTerminal
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any reason why we export things conditionally like this? I think it might break several test files like tests/tools/terminal/test_session_factory.py.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

else, it will raise ModuleNotFoundError: No module named 'fcntl'
https://github.com/OpenHands/OpenHands/issues/11629

logger.info("Using forced TmuxTerminal")
terminal = TmuxTerminal(work_dir, username)
return TerminalSession(terminal, no_change_timeout_seconds)
elif terminal_type == "subprocess":
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since SubprocessTerminal depends on fcntl which isn't available on Windows, should we add a if platform.system() == "Windows": check here and raise RuntimeError?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line 86 will run only when terminal_type== "subprocess" is specified and None is the default value for that.

@SmartManoj
Copy link
Contributor Author

SmartManoj commented Nov 17, 2025

I saw it first attempted to run a bash command

Does this tool description need to be updated?

TOOL_DESCRIPTION = """Execute a bash command in the terminal within a persistent shell session.

@xingyaoww
Copy link
Collaborator

@SmartManoj

Does this tool description need to be updated?

Yes we should either phrase it so the description is general enough, OR we should implement a switch (i.e., only change the description if windows is selected as the terminal implementation)

Introduces TOOL_DESCRIPTION_FOR_WINDOWS for PowerShell commands and updates TerminalTool to select the appropriate description based on the platform. This improves clarity and guidance for users on both Unix and Windows systems.
@SmartManoj
Copy link
Contributor Author

image

@ryanhoangt ryanhoangt self-requested a review November 18, 2025 14:36
Copy link
Collaborator

@ryanhoangt ryanhoangt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great and LGTM, thank you!

Copy link
Collaborator

@xingyaoww xingyaoww left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ryanhoangt, can we potentially get LLM-back integration tests running on Windows as well? Maybe in a subsequent PR

--cov-report=term-missing `
--cov-fail-under=0 `
--cov-config=pyproject.toml `
tests/tools/terminal/test_windows_terminal.py
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we run all the tests here instead of just the terminal one?

Ideally we should check all things are working on Windows (maybe just skip subprocess/tmux terminals).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#1209 - Follow up

Deleted the [tool.coverage.paths] section, which specified source paths for coverage analysis. This simplifies the configuration and may indicate a change in how coverage is managed or reported.
@SmartManoj
Copy link
Contributor Author

Pre-requisite #1014?

@enyst
Copy link
Collaborator

enyst commented Nov 20, 2025

Pre-requisite #1014?

Are the failing tests browser tests? That PR only refers to the browser tool.

@SmartManoj
Copy link
Contributor Author

image

@enyst
Copy link
Collaborator

enyst commented Nov 20, 2025

When I look at the failed github action, I see 69 tests failed:

...
ERROR tests/tools/file_editor/test_basic_operations.py::test_view_operation_truncation - PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'C:\\Users\\RUNNER~1\\AppData\\Local\\Temp\\tmpsqa3coyk'
ERROR tests/tools/file_editor/test_error_handling.py::test_str_replace_error_handling - PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'C:\\Users\\RUNNER~1\\AppData\\Local\\Temp\\tmphasdsv36'
ERROR tests/tools/file_editor/test_error_handling.py::test_view_range_validation - PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'C:\\Users\\RUNNER~1\\AppData\\Local\\Temp\\tmp1_4_wj1l'
ERROR tests/tools/file_editor/test_error_handling.py::test_insert_validation - PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'C:\\Users\\RUNNER~1\\AppData\\Local\\Temp\\tmp8005bwo_'
ERROR tests/tools/file_editor/test_error_handling.py::test_undo_validation - PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'C:\\Users\\RUNNER~1\\AppData\\Local\\Temp\\tmpcgu4pil1'
= 69 failed, 314 passed, 24 skipped, 36 warnings, 32 errors in 192.79s (0:03:12) =
Windows tools coverage file prepared for upload
Error: Process completed with exit code 1.

Seems like file editor tests are failing, not just browser?

@SmartManoj
Copy link
Contributor Author

image

yield file_path
# On Windows, files may be locked briefly after handles are closed.
# This is due to Windows file system behavior where file handles may not be
# immediately released, opportunistic locks (oplocks), or background processes
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this affect other behaviors too, not just current tests? 🤔

Deleted the [tool.coverage.report] section and its ignore_errors setting from pyproject.toml, likely to simplify coverage configuration or rely on defaults.
Moved the Unix and Windows terminal tool descriptions to separate template files and updated the code to load them dynamically. This improves maintainability and allows easier updates to the descriptions without modifying the Python source.
Renamed unix and windows terminal description templates from .txt to .j2 for consistency with Jinja2 template naming. Updated references in definition.py and included the new template files in the agent-server.spec data collection.
@SmartManoj SmartManoj requested a review from xingyaoww November 21, 2025 06:18
@blacksmith-sh
Copy link
Contributor

blacksmith-sh bot commented Nov 26, 2025

[Automatic Post]: It has been a while since there was any activity on this PR. @SmartManoj, are you still working on it? If so, please go ahead, if not then please request review, close it, or request that someone else follow up.

1 similar comment
@blacksmith-sh
Copy link
Contributor

blacksmith-sh bot commented Dec 1, 2025

[Automatic Post]: It has been a while since there was any activity on this PR. @SmartManoj, are you still working on it? If so, please go ahead, if not then please request review, close it, or request that someone else follow up.

Copy link
Collaborator

@xingyaoww xingyaoww left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually @SmartManoj could we combine #1209 with this PR - so we can be sure the windows terminal is working as expected before we merge it? Thanks!

@SmartManoj
Copy link
Contributor Author

Pre-requisite #1014?

@xingyaoww

@enyst
Copy link
Collaborator

enyst commented Dec 1, 2025

Pre-requisite #1014?

I'm happy to unblock that issue. I think there is a bit of a discussion in the related issue on how exactly we design the code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants